package com.supor.md_video.adapter;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.baseconfig.base.GlideApp;
import com.android.baseconfig.base.GlideRequest;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.supor.aiot.common.utils.NotNullUtils;
import com.supor.md_video.R;
import com.supor.md_video.entity.VideoCommListBean;
import com.supor.md_video.tools.NumberUtils;

import java.util.ArrayList;

import androidx.annotation.NonNull;

public class CommListAdapter extends BaseQuickAdapter<VideoCommListBean, BaseViewHolder> implements LoadMoreModule {
    public CommListAdapter() {
        super(R.layout.item_video_comm, new ArrayList<>());
        addChildClickViewIds(R.id.ll_video_comm_thumb);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoCommListBean item) {
        GlideRequest<Drawable> glideRequests;
        String avaStr = NotNullUtils.getNotNullValue(item.getHeadPortaint(), "0");
        switch (avaStr) {
            case "0":
                glideRequests = GlideApp.with(getContext()).load(R.mipmap.ic_default_head);
                break;
            case "1":
                glideRequests = GlideApp.with(getContext()).load(R.mipmap.ic_default_head1);
                break;
            case "2":
                glideRequests = GlideApp.with(getContext()).load(R.mipmap.ic_default_head2);
                break;
            case "3":
                glideRequests = GlideApp.with(getContext()).load(R.mipmap.ic_default_head3);
                break;
            case "4":
                glideRequests = GlideApp.with(getContext()).load(R.mipmap.ic_default_head4);
                break;
            default:
                glideRequests = GlideApp.with(getContext()).load(avaStr);
                break;
        }
        glideRequests.into((ImageView) baseViewHolder.getView(R.id.iv_ava));

        ((TextView) baseViewHolder.getView(R.id.tv_nick_name))
                .setText(TextUtils.isEmpty(item.getNickName()) ? "" : item.getNickName());
        ((TextView) baseViewHolder.getView(R.id.tv_comm_date))
                .setText(TextUtils.isEmpty(item.getCreateTime()) ? "" : item.getCreateTime());
        ((TextView) baseViewHolder.getView(R.id.tv_content))
                .setText(TextUtils.isEmpty(item.getReplyContent()) ? "" : item.getReplyContent());
        TextView tvThumbsNum = baseViewHolder.getView(R.id.tv_thumbs_num);
        tvThumbsNum.setText(NumberUtils.formatNum(item.getLikeCount()));
        tvThumbsNum.setTextColor(item.getIsLike() == 1 ? 0xffff9b00 : 0xff999999);

        baseViewHolder.setBackgroundResource(R.id.iv_thumb_icon,
                item.getIsLike() == 1 ? R.mipmap.ic_thumbs_light : R.mipmap.ic_thumbs_gray);
    }
}
